﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Entidad;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
    public class RestauradorDAO : InformeRestauracionInterface
    {
        private DAO_v2 dao;
        public DataView BuscarRestauradores(Int64? cuil)
        {
            {
                dao = new DAO_v2();
                SqlConnection con = new SqlConnection(DAO_v2.MiCadenaConexion());
                try
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand();
                    String consulta = "SELECT ";
                    consulta += "id_Restaurador, (p.apellido + ', ' + p.nombre + ' ('+ CAST(r.cuil as varchar(13))+')') AS datos ";
                    consulta += "FROM ";
                    consulta += "Restaurador r INNER JOIN Persona p ON p.id_Persona = r.id_Persona ";
                    consulta += "WHERE 1 = 1 ";
                    if (cuil.HasValue)
                    {
                        consulta += "AND r.cuil = @cuil";
                        cmd.Parameters.AddWithValue("@cuil", cuil);
                    }
                    cmd.CommandText = consulta;
                    cmd.Connection = con;
                    DataTable dt = new DataTable();
                    dt.Load(cmd.ExecuteReader());
                    DataView resultado = new DataView(dt);
                    return resultado;
                }
                catch (SqlException ex)
                {
                    return null;
                    throw new ApplicationException("Error al buscar los Restauradores...");
                }
                finally
                {
                    dao.CerrarConexion(con);
                }
            }
        }


        public List<EjemplarEnt> BuscarEjemplares(int? codigo)
        {
            throw new NotImplementedException();
        }


        public DataView ObtenerInforme()
        {
            throw new NotImplementedException();
        }


        public DataView ObtenerInforme(String filtro)
        {
            throw new NotImplementedException();
        }


        public string OtenerFechaMasAntigua()
        {
            throw new NotImplementedException();
        }
    }
}
